<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Crop an image to the given rectangle</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.imagecrop" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">imagecrop</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.5.0, PHP 7)</p><p class="refpurpose"><span class="refname">imagecrop</span> &mdash; <span class="dc-title">Crop an image to the given rectangle</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.imagecrop-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>imagecrop</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$image</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter">$rect</code></span>
   ) : <span class="type">resource</span></div>

  <p class="para rdfs-comment">
   Crops an image to the given rectangular area and returns the resulting image.
   The given <code class="parameter">image</code> is not modified.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-function.imagecrop-parameters">
  <h3 class="title">参数</h3>
  <dl>

   <dt>
<code class="parameter">image</code></dt>

<dd>
<p class="para">由图象创建函数(例如<span class="function"><a href="imagecreatetruecolor.html" class="function">imagecreatetruecolor()</a></span>)返回的图象资源。</p></dd>

   
    <dt>
<code class="parameter">rect</code></dt>

    <dd>

     <p class="para">
      The cropping rectangle as <span class="type"><a href="language.types.array.html" class="type array">array</a></span> with keys
      <em>x</em>, <em>y</em>, <em>width</em> and
      <em>height</em>.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.imagecrop-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Return cropped image resource on success 或者在失败时返回 <strong><code>FALSE</code></strong>.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.imagecrop-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-3690">
   <p><strong>Example #1 <span class="function"><strong>imagecrop()</strong></span> example</strong></p>
   <div class="example-contents"><p>
     This example shows how to crop an image to a square area.
   </p></div>
   <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$im&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecreatefrompng</span><span style="color: #007700">(</span><span style="color: #DD0000">'example.png'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$size&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">min</span><span style="color: #007700">(</span><span style="color: #0000BB">imagesx</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">imagesy</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$im2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecrop</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;[</span><span style="color: #DD0000">'x'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'y'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'width'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$size</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'height'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$size</span><span style="color: #007700">]);<br />if&nbsp;(</span><span style="color: #0000BB">$im2&nbsp;</span><span style="color: #007700">!==&nbsp;</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">imagepng</span><span style="color: #007700">(</span><span style="color: #0000BB">$im2</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'example-cropped.png'</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">imagedestroy</span><span style="color: #007700">(</span><span style="color: #0000BB">$im2</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">imagedestroy</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
   </div>

  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.imagecrop-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="function"><a href="imagecropauto.html" class="function" rel="rdfs-seeAlso">imagecropauto()</a> - Crop an image automatically using one of the available modes</span></li>
  </ul>
 </div>


</div></div></div></body></html>